import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { GetListDto } from 'src/interface';
import { Resource } from 'src/models/resource';
import { ResourceService } from './resource.service';

@Controller(`resource`)
export class ResourceController {
  constructor(private readonly resourceService: ResourceService) {}

  @Get('/count')
  async getCount(): Promise<number> {
    return await this.resourceService.getCount();
  }

  @Get('/getAll')
  async findAll(): Promise<Resource[] | null> {
    return await this.resourceService.findAll();
  }

  @Get(':id')
  async findOne(@Param('id') id: string): Promise<Resource[] | null> {
    return await this.resourceService.findOne(id);
  }

  @Post('/getList')
  async findList(@Body() getListDto: GetListDto): Promise<Resource[] | null> {
    return await this.resourceService.findList(getListDto);
  }

  @Post('/create')
  async createItem(@Body() createDto: Resource): Promise<Resource> {
    return await this.resourceService.createData(createDto);
  }

  @Post('/update/:id')
  async upDataItem(
    @Param('id') id: string,
    @Body() upDataUserDto: Resource,
  ): Promise<Resource[] | null> {
    return await this.resourceService.updateData(id, upDataUserDto);
  }

  @Post('/remove/:id')
  async removeItem(@Param('id') id: string): Promise<any> {
    return await this.resourceService.removeData(id);
  }

  @Post('/delete')
  async deleteItems(@Body() deleteMenusDto: string[]): Promise<any> {
    return await this.resourceService.deleteData(deleteMenusDto);
  }
}
